module game {
	/**
	 * 页面6
	 * @author caizj 2015-08-12
	 *
	 */
    export class SwiperPage7 extends BaseSwiper {
        private bg: egret.Bitmap;//背景
        private game_logo: egret.Bitmap;//游戏logo
        private game_slogan: egret.Bitmap;//游戏slogan
        private download_btn: egret.Bitmap;//下载按钮
        private slogan_ui: egret.DisplayObjectContainer;//包含download_btn+game_slogan
        private urlloader: egret.URLLoader;
        private video: any;

        public constructor() {
            super();
        }

        public activate(): void {
            if(this.isActive) return;

            super.activate();
            //            console.log("激活page3");
            if(this.bg == null) {
                this.bg = this.createBitmapByName("page7_bg_png");
                this.addChild(this.bg);
                this.bg.x = this.bg.y = 0;
            }
            if(this.slogan_ui == null) {
                this.slogan_ui = new egret.DisplayObjectContainer();
                this.addChild(this.slogan_ui);
            }
            if(this.game_logo == null) {
                this.game_logo = this.createBitmapByName("page7_logo");
                this.addChild(this.game_logo);
            }
            if(this.game_slogan == null) {
                this.game_slogan = this.createBitmapByName("page7_slogan");
                this.slogan_ui.addChild(this.game_slogan);
            }
            if(this.download_btn == null) {
                this.download_btn = this.createBitmapByName("download_btn_png");
                this.download_btn.touchEnabled = true;
                this.download_btn.name = "download";
                this.slogan_ui.addChild(this.download_btn);
                this.download_btn.x = 198;
                this.download_btn.y = 857;
                this.download_btn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.gotoLink,this,false,1);
            }
            //从上面落入
            this.game_logo.x = 0;
            this.game_logo.y = -500;
            this.game_logo.visible = true;
                        
            //从下放弹出
            this.slogan_ui.x = 0;
            this.slogan_ui.y = 500;
            this.slogan_ui.visible = false;
         
            //入场动画             
            //从上面落入
            egret.Tween.get(this.game_logo).to({ y: 0 },400,egret.Ease.sineOut).call(this.onTweenOver,this,[this.game_logo]);
            
            //从下方弹出
            egret.Tween.get(this.slogan_ui).wait(500).to({ y: 0 },200,egret.Ease.elasticOut).call(this.onTweenOver,this,[this.slogan_ui]);                       
                                  
            //播放入场音效
            //            this.playSound();
        }

        public deactivate(): void {
            if(!this.isActive) return;

            super.deactivate();
            //            console.log("静止page1");
                                    
            if(this.bg == null) {
                this.bg = this.createBitmapByName("page7_bg_png");
                this.addChild(this.bg);
            }
            if(this.game_logo) {
                this.game_logo.visible = false;
            }
            if(this.slogan_ui) {
                this.slogan_ui.visible = false;
            }
//            this.hideVideo();
        }

        protected onTweenOver(obj: any): void {
            super.onTweenOver(obj);
            
            //logo动画结束后，显示文字图片
            if(obj == this.game_logo) {
                this.slogan_ui.visible = true;
                //播放入场音效
                this.playSound();
            } else { 
//                this.showVideo();
            }
        }
        
        /**跳转下载链接**/
        private gotoLink(event: egret.TouchEvent): void {
            console.log("gotoLink");
            event.preventDefault();
            
            //原生js接口
            window.open("http://cb.caohua.com/",'_blank');
            //            window.navigate("http://cb.caohua.com/"); 
            //egret接口
            //            this.urlloader = new egret.URLLoader();
            //            var urlreq:egret.URLRequest = new egret.URLRequest();
            //            urlreq.url = "http://cb.caohua.com/";
            //            this.urlloader.load( urlreq );
            //            this.urlloader.addEventListener(egret.Event.COMPLETE, this.onComplete, this);
            //            JsonpReq.process(this.urlloader);
            //            console.log(urlreq.url);
            //            
            //            event.preventDefault();
        }
        private onComplete(event: egret.Event): void {
            console.log(this.urlloader.data);
        }

        /**播放视频[显示]**/
        private showVideo(): void {
            if(this.video == null) { 
                this.video = document.createElement("video");
                this.video.width = 200;
                this.video.height = 200;
                this.video.style.top = "-1000px";
                this.video.style.left = "300px";
                this.video.autoplay = true;
                this.video.controls=true;
                this.video.loop = true;
                this.video.src = "resource/assets/movie.mp4";
                this.video.load();
                document.body.appendChild(this.video);
            }
            this.video.play();
            this.video.style.display = "block";
        }

        /**停止视频[隐藏]**/
        private hideVideo():void{
            if(this.video == null)  return;
            
            if(this.video.played){
                this.video.pause();
            }
            this.video.style.display = "none";
        }
	}
}
